package com.occupation_health.model;

import java.util.Date;
import java.util.List;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.LockedAccountException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import com.jfinal.plugin.activerecord.Model;
import com.occupation_health.common.function;

public class UserApi extends Model<UserApi> {
	public static final UserApi dao = new UserApi().dao();

	public UserApi getByUserName(String userName) {
		UserApi user = UserApi.dao
				.findFirst("SELECT * FROM oh_user a WHERE a.username='"
						+ userName + "'");
		return user;
	}


	/*
	 * 注册
	 * 
	 * @param username=用户名
	 * 
	 * @param password=密码
	 */
	public void register(String username, String password) {
		this.set("username", username)
				.set("password", password)
				.set("register_time",
						function.getSecondTimestampTwo(new Date())).save();
	}

	/*
	 * 列出指定条件的用户
	 * 
	 * @param String column 字段名
	 * 
	 * @param String condition 条件
	 * 
	 * @param String value 值
	 * 
	 * @return List<UserApi> 选中的用户集合
	 */
	public List<UserApi> getUserList(String column, String condition,
			String value) {
		List<UserApi> result = UserApi.dao.find("SELECT * FROM oh_user WHERE "
				+ column + condition + "'" + value + "'");
		return result;
	}

	/*
	 * 列出所有用户
	 * 
	 * @return List<userApi> 所用用户集合
	 */
	public List<UserApi> getUserList() {
		List<UserApi> result = UserApi.dao.find("SELECT * FROM oh_user");
		return result;
	}
	
	public boolean unique() {
		return false;
	}

}
